from configparser import ConfigParser, NoOptionError, NoSectionError
import os


# file = '../conf/conf.ini'


class HandleConf(ConfigParser):
    def __init__(self, conf_path):
        super().__init__()
        conf_path = '../conf/' + conf_path
        if not os.path.exists(conf_path):
            raise FileNotFoundError('文件不存在')
        self.file = conf_path
        self.read(self.file, encoding='utf-8')

    def get_value(self, section, option):
        try:
            value = self.get(section, option)
            return value
        except(NoSectionError, NoOptionError) as e:
            print(f'获取配置出错：{e}')
            return e


# path =HandleConf('page.ini').get_value('search', 'search_input_method')
# path2 =HandleConf('page.ini').get_value('search', 'search_input_element')
# print(path,path2)
# handle_conf = HandleConf(path)
# print(handle_conf)
# a =HandleConf('page.ini')
# print(a)